﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Assimp;
using OpenTK;

namespace Common {
    public class AssimpLoader {
        public static bool Load(string path, List<ushort> indices, List<Vector3> vertices, List<Vector2> uvs, List<Vector3> normals) {
            AssimpContext importer = new AssimpContext();
            Scene scene = importer.ImportFile(path);
            if (scene == null) {
                throw new Exception("open failed!");
            }
            Mesh mesh = scene.Meshes[0];
            for (int i = 0; i < mesh.Vertices.Count; i++) {
                var pos = mesh.Vertices[i];
                vertices.Add(new Vector3(pos.X, pos.Y, pos.Z));
                var UVW = mesh.TextureCoordinateChannels[0][i];
                uvs.Add(new Vector2(UVW.X, UVW.Y));
                var normal = mesh.Normals[i];
                normals.Add(new Vector3(normal.X, normal.Y, normal.Z));
            }

            for (int i = 0; i < mesh.Faces.Count; i++) {
                indices.Add((ushort)mesh.Faces[i].Indices[0]);
                indices.Add((ushort)mesh.Faces[i].Indices[1]);
                indices.Add((ushort)mesh.Faces[i].Indices[2]);
            }

            return false;
        }
    }
}
